//
//  GCMBuildingViewController.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/3/16.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMBuildingViewController.h"
#import "GCMEntranceViewController.h"

@interface GCMBuildingViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation GCMBuildingViewController{
    
    NSMutableArray *_dataSource;
    UITableView *_tableV;
}
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
    [self downLoadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self createTableView];
    [self downLoadData];
    
    
    
}

-(void)createTableView{
    
    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT )];
    _tableV.delegate = self;
    _tableV.dataSource =self;
    _tableV.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    [self.view addSubview:_tableV];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell setBackgroundColor:[UIColor colorWithRed:.93 green:.93 blue:.93 alpha:1]];
    cell.textLabel.text = [_dataSource[indexPath.row] valueForKey:@"name"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.textColor = [UIColor colorWithRed:0.39 green:0.39 blue:0.39 alpha:1];
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMEntranceViewController * entranlVC = [[GCMEntranceViewController alloc]init];
    entranlVC.numberVC = self.numberVC;
    entranlVC.areaID = self.areaID;
    entranlVC.areaName = self.areaName;
    entranlVC.buildID = [_dataSource[indexPath.row] valueForKey:@"id"];
    entranlVC.buildName = [_dataSource[indexPath.row] valueForKey:@"name"];
    [self.navigationController pushViewController:entranlVC animated:YES ];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"单元选择";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
}


-(void)downLoadData{
    
    [GCMHostSearchHttpRequst postDataWithcourtId:self.areaID Success:^(id obj, NSError *err) {
        _dataSource  = obj;
        NSLog(@"楼座%@",_dataSource);
        [_tableV reloadData];
    }];
}

-(void)initData{
    
    _dataSource = [[NSMutableArray alloc]init];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
